package com.cskaoyan.controller.wx_xd;

import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.MarketGoods;
import com.cskaoyan.bean.collect.CollectBo;
import com.cskaoyan.bean.collect.CollectListVo;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.service.CollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Austin Hsu
 * @Date 2022/9/12 11:02
 */
@RestController
@RequestMapping("wx/collect")
public class CollectController {



    @Autowired
    CollectionService collectionService;

    /**
     * 两张表：market_collect --- market_goods
     * @param
     * @param info
     * @return
     */
    @RequestMapping("list")                                    //微信前端好像没有实现type=1的收藏
    public BaseRespVo list(String type,BasePageInfo info) {      //marketCollect得到type 可以直接传type吗 --然而这个type在查询中没用到
        CommonData<CollectListVo> data=collectionService.query(type,info);
        return BaseRespVo.ok2(data);
    }


    /**
     * 客户端 收藏和删除收藏 发的请求体是同一个 ---> {"type":0,"valueId":1127003}
     * 1.先根据user_id和value_id   select 表market_collect中是否有这条数据
     * 2.如果有这条数据 判断这条数据在表中的deleted属性为0还是1  是0则update delete=1 是1则update deleted=0
     *   如果没有这条数据 insert这条数据
     * @param collectBo
     * @return
     */
    @RequestMapping("addordelete")
    public BaseRespVo addordelete(@RequestBody CollectBo collectBo) {
        collectionService.addordelete(collectBo);
        return BaseRespVo.ok3();
    }


}
